Passed
Push — master ( 33081a...0dd98d )
by Paul
05:28
created

site-reviews-admin.js ➔ x   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 72

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
nc 4
nop 0
dl 0
loc 72
rs 9.102
c 1
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A site-reviews-admin.js ➔ ... ➔ ???.onInit 0 3 1
A site-reviews-admin.js ➔ jQuery 0 51 1
A site-reviews-admin.js ➔ ... ➔ ???.onResultClick 0 14 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
/** global: GLSR, jQuery */
2
3
GLSR.keys = {
4
	DOWN: 40,
5
	ENTER: 13,
6
	ESC: 27,
7
	SPACE: 32,
8
	UP: 38,
9
};
10
11
jQuery( function() {
12
	GLSR.ColorPicker();
13
	new GLSR.Forms( 'form.glsr-form' );
14
	new GLSR.Logger();
15
	new GLSR.Pinned();
16
	new GLSR.Pointers();
17
	new GLSR.Search( '#glsr-search-posts', {
18
		action: 'search-posts',
19
		onInit: function() {
20
			this.el.on( 'click', '.glsr-remove-button', this.onUnassign_.bind( this ));
21
		},
22
		onResultClick: function( ev ) {
23
			var result = x( ev.target );
24
			var template = wp.template( 'glsr-assigned-post' );
0 ignored issues
show
Bug introduced by
The variable wp seems to be never declared. If this is a global, consider adding a /** global: wp */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
25
			var entry = {
26
				url: result.data( 'url' ),
27
				title: result.text(),
28
			};
29
			if( template ) {
30
				this.el.find( 'input#assigned_to' ).val( result.data( 'id' ));
31
				this.el.find( '.description' ).html( template( entry ));
32
				this.el.on( 'click', '.glsr-remove-button', this.onUnassign_.bind( this ));
33
				this.reset_();
34
			}
35
		},
36
	});
37
	new GLSR.Search( '#glsr-search-translations', {
38
		action: 'search-translations',
39
		onInit: function() {
40
			this.makeSortable_();
41
		},
42
		onResultClick: function( ev ) {
43
			var result = x( ev.target );
44
			var entry = result.data( 'entry' );
45
			var template = wp.template( 'glsr-string-' + ( entry.p1 ? 'plural' : 'single' ));
0 ignored issues
show
Bug introduced by
The variable wp seems to be never declared. If this is a global, consider adding a /** global: wp */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
46
			entry.index = this.options.entriesEl.children().length;
47
			entry.prefix = this.options.resultsEl.data( 'prefix' );
48
			if( template ) {
49
				this.options.entriesEl.append( template( entry ));
50
				this.options.exclude.push({ id: entry.id });
51
				this.options.results = this.options.results.filter( function( i, el ) {
52
					return el !== result.get(0);
53
				});
54
			}
55
			this.setVisibility_();
56
		},
57
	});
58
	new GLSR.Status( 'a.glsr-change-status' );
59
	new GLSR.Tabs();
60
	new GLSR.TextareaResize();
61
});
62